#include "../serve.hpp"

class EchoServe
{
private:
    TcpServe _tcpserve;

private:
    void OnConnected(const PtrConnection &conn)
    {
        DBG_LOG("NEW CONNECTION:%p", conn.get());
    }
    void OnClosed(const PtrConnection &conn)
    {
        DBG_LOG("CLOSE CONNECTION:%p", conn.get());
    }
    void OnMessage(const PtrConnection &conn, Buffer *buf)
    {
        conn->Send(buf->ReadPOS(), buf->ReadSpace());
        buf->MoveReadInd(buf->ReadSpace());
    }

public:
    EchoServe() : _tcpserve(8089)
    {
        _tcpserve.SetClosedCallback(std::bind(&EchoServe::OnClosed,this,std::placeholders::_1));
        _tcpserve.SetConnectedCallback(std::bind(&EchoServe::OnConnected,this,std::placeholders::_1));
        _tcpserve.SetMessageCallback(std::bind(&EchoServe::OnMessage,this,std::placeholders::_1,std::placeholders::_2));
        _tcpserve.EnableInactiveRelase(10);
        _tcpserve.SetThreadCount(3);
        
    }
    void Start()
    {
        _tcpserve.Start();
    }
};